﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinMenuBar.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win menu bar.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using System.Collections.Generic;
    using System.Linq;

    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win menu bar.
    /// </summary>
    public class CuitWinMenuBar : CuitWinControl<WinMenuBar>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinMenuBar" /> class.
        /// </summary>
        public CuitWinMenuBar()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinMenuBar"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinMenuBar(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinMenuBar"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinMenuBar(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinMenuBar"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinMenuBar(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinMenuBar"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinMenuBar(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinMenuBar"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinMenuBar(ICuitControlBase wrappedControl, string searchProperties, string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets the items.
        /// </summary>
        public UITestControlCollection Items
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Items;
            }
        }

        /// <summary>
        ///     Gets the items as cui te.
        /// </summary>
        public List<CuitWinMenuItem> ItemsAsASTControl
        {
            get
            {
                this._control.WaitForControlReady();
                var list = new List<CuitWinMenuItem>();
                foreach (WinMenuItem item in this._control.Items)
                {
                    var cuiteItem = new CuitWinMenuItem();
                    cuiteItem.WrapReady(item);
                    list.Add(cuiteItem);
                }

                return list;
            }
        }

        /// <summary>
        ///     Gets the items as list.
        /// </summary>
        public List<string> ItemsAsList
        {
            get
            {
                this._control.WaitForControlReady();
                return (from x in this._control.Items select ((WinMenuItem)x).DisplayText).ToList<string>();
            }
        }

        #endregion
    }
}